package com.ruoyi.contract.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import com.ruoyi.common.utils.order.OrderUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.contract.domain.TContractInfo;
import com.ruoyi.contract.service.ITContractInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 合同信息Controller
 * 
 * @author wzy
 * @date 2024-08-29 10:21:31
 */
@RestController
@RequestMapping("/contracts/contract")
public class TContractInfoController extends BaseController
{
    @Autowired
    private ITContractInfoService tContractInfoService;

    /**
     * 查询合同信息列表
     */
    @PreAuthorize("@ss.hasPermi('contracts:contract:list')")
    @GetMapping("/list")
    public TableDataInfo list(TContractInfo tContractInfo)
    {
        startPage();
        List<TContractInfo> list = tContractInfoService.selectTContractInfoList(tContractInfo);
        return getDataTable(list);
    }

    /**
     * 导出合同信息列表
     */
    @PreAuthorize("@ss.hasPermi('contracts:contract:export')")
    @Log(title = "合同信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TContractInfo tContractInfo)
    {
        List<TContractInfo> list = tContractInfoService.selectTContractInfoList(tContractInfo);
        ExcelUtil<TContractInfo> util = new ExcelUtil<TContractInfo>(TContractInfo.class);
        util.exportExcel(response, list, "合同信息数据");
    }

    /**
     * 获取合同信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('contracts:contract:query')")
    @GetMapping(value = "/{contractId}")
    public AjaxResult getInfo(@PathVariable("contractId") Long contractId)
    {
        return success(tContractInfoService.selectTContractInfoByContractId(contractId));
    }

    /**
     * 新增合同信息
     */
    @PreAuthorize("@ss.hasPermi('contracts:contract:add')")
    @Log(title = "合同信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TContractInfo tContractInfo)
    {
        tContractInfo.setContractNumber(OrderUtils.getOrderNumber("CN", "-"));
        tContractInfo.setCreateBy(getNickName());
        return toAjax(tContractInfoService.insertTContractInfo(tContractInfo));
    }

    /**
     * 修改合同信息
     */
    @PreAuthorize("@ss.hasPermi('contracts:contract:edit')")
    @Log(title = "合同信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TContractInfo tContractInfo)
    {
        tContractInfo.setUpdateBy(getNickName());
        return toAjax(tContractInfoService.updateTContractInfo(tContractInfo));
    }

    /**
     * 删除合同信息
     */
    @PreAuthorize("@ss.hasPermi('contracts:contract:remove')")
    @Log(title = "合同信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{contractIds}")
    public AjaxResult remove(@PathVariable Long[] contractIds)
    {
        return toAjax(tContractInfoService.deleteTContractInfoByContractIds(contractIds));
    }
}
